import { InvokeResponseCode } from '@/common/constant'

export class InvokeResponse {
  code: string | undefined
  message: string | '' | undefined
  data: unknown

  constructor(code: string, message?: string, data?: unknown) {
    this.code = code
    this.message = message
    this.data = data
  }

  static success(message?: string, data?: unknown) {
    return new InvokeResponse(InvokeResponseCode.Success, message, data)
  }

  static data(data: unknown) {
    return new InvokeResponse(InvokeResponseCode.Success, '', data)
  }

  static fail(message: string, data?: unknown) {
    return new InvokeResponse(InvokeResponseCode.Fail, message, data)
  }

  isSuccess() {
    return this.code === InvokeResponseCode.Success
  }
}
